class IndexView extends zysx.BaseView{
	//开始游戏
	private btn_start:eui.Button;
	//排名
	private btn_pm:eui.Image;
	//分享
	private img_share:eui.Image;
	//关于
	private about:eui.Image;

	//登录礼包
	private giftGroup:eui.Group;

	private gift:eui.Image;


	public constructor(data?) {
		super(data);
		this.skinName = "IndexSkin";
	}


	public initComponent(): void {
		super.initComponent();
	}

	public initListener(): void {
		super.initListener();
		
		this.addEvent(this.btn_start, egret.TouchEvent.TOUCH_TAP, this.openView, this);	
		this.addEvent(this.about,egret.TouchEvent.TOUCH_TAP, this.openView, this);
		this.addEvent(this.btn_pm,egret.TouchEvent.TOUCH_TAP, this.openView, this);
		this.addEvent(this.img_share,egret.TouchEvent.TOUCH_TAP, this.share, this);
		
	}

	public share(): void{
		ShareMgr.share();
	}

	public onOpen(data?): void {
		super.onOpen(data);
		this.initView();
	}
	private initView(): void {
		this.checkGift();
		
		var obj = this.data;
		if(obj){
			if(obj.target == Consts.HELP){
				obj.flg = 4;
				zysx.LayerMgr.ins.openView(ViewConst.TIPPANEL, obj, LayerType.POP);
			}else if(obj.target == Consts.TONG_GUAN){
				obj.flg  = 3;
				zysx.LayerMgr.ins.openView(ViewConst.TIPPANEL, obj, LayerType.POP);
			}
		}
	}

	//检查新手礼包
	private checkGift():void{
		let nowDate  = new Date();
		let key = nowDate.getFullYear().toString() + nowDate.getMonth().toString() + nowDate.getDate().toString();
		if(UserMgr.ins.giftTime != key){
			this.addEvent(this.giftGroup,egret.TouchEvent.TOUCH_TAP, this.openView, this);
			this.giftGroup.visible = true;
			var tw = egret.Tween.get( this.gift, { loop:true} );
			tw.to({rotation:-20},120)
				.to({rotation:20},240)
				.to({rotation:-20},360)
				.to({rotation:0},480).wait(3600);

			zysx.LayerMgr.ins.openView(ViewConst.FULIVIEW, 1, LayerType.POP);	
		}
	}


	private openView(evt: egret.TouchEvent): void {
		let viewName: string = "";
		let layType: number = LayerType.UI;
		let data = null;
		switch (evt.currentTarget) {
			case this.btn_start:
				viewName = ViewConst.PLAYVIEW;
				data = 1;
				break;
			case this.btn_pm:
				viewName = ViewConst.RANKVIEW;
				data = 1;
				break;
			case this.about:
				viewName = ViewConst.ABOUTVIEW;
				data = 1;
				break;	
			case this.giftGroup:
				layType = LayerType.POP;
				viewName = ViewConst.FULIVIEW
				data = 1;
				break;

		}
		if (viewName!="") {
			zysx.LayerMgr.ins.openView(viewName, data, layType);
		}
	}
}
window["IndexView"] = IndexView;